{include file="header/index" /}
<style>
  .form-control {
    height: 33px;
  }
</style>
<div class="newContentBox">
  <div class="fixedFather">
    <div class="fix">
      编辑用户组
      <span class="newNotice"><span class="newtext">*</span>为必填项</span>
      <div class="newFixBtnBox">
        <button type="button" class="newBtnDefault newBtnGray" onclick="returnBack(this)"> <i
            class="fa fa-mail-reply"></i>返回</button>
      </div>
    </div>
  </div>
  <form class="layui-form newListPart " name="userAdd" id="userAdd" action="{:url('Authgroup/edit')}">
    <input name="id" type="hidden" value="{$data.id}" />
    <div class="newPart">
      <div class="newTitle">
        <i class="fa fa-address-book allColor icon"></i> 基本信息
      </div>
      <div class="newContent">
        <div class="layui-form-item cover_layui_f_i">
          <label class="layui-form-label cover_layui_f_l"><span class="cover_new_label">*</span> 用户组名称</label>
          <div class="layui-input-block cover_layui_i_b">
            <input type="text" id="title" type="text" name="title" required lay-verify="required" placeholder="请输入用户组名称"
              autocomplete="off" class="layui-input" value="{$data.title}">
          </div>
        </div>
        <div class="layui-form-item cover_layui_f_i">
          <label class="layui-form-label cover_layui_f_l"><span class="cover_new_label">*</span> 角色</label>
          <div class="layui-input-block cover_layui_i_b">
            <select name="role" id="role" lay-verify="required">
              {foreach $role as $k =>$v}
              <option value="{$k}" {if condition="$data.role eq $k" } selected {/if}>{$v} </option> {/foreach} </select>
                </div> </div> <div class="layui-form-item cover_layui_f_i">
                <label class="layui-form-label cover_layui_f_l"><span class="cover_new_label">*</span> 状态</label>
                <div class="layui-input-block cover_layui_i_b">
                  <input type="checkbox" name="status" value="1" lay-skin="primary" title="默认开启" {if
                    condition="$data['status'] eq 1" }checked {/if}> </div> </div> </div> <div class="layui-form-item ">
                  <div class="layui-input-block cover_layui_i_b">
                    <button class="layui-btn newBtnDefault newBtnPrimary" lay-submit lay-filter="formDemo">保存</button>
                    <button type="reset" class="layui-btn newBtnDefault">重置</button>
                  </div>
                </div>
          </div>
  </form>
</div>
<script>
  var layer = layui.layer,
    element = layui.element,
    laydate = layui.laydate,
    laypage = layui.laypage,
    form = layui.form,
    upload = layui.upload,
    layedit = layui.layedit;
  form.render();
  //重置
  function reset() {
    top.layer.confirm('你确定要重置吗?', {
      btn: ['确定', '取消'] //按钮
    }, function () {
      $("#userAdd")[0].reset();
      top.layer.msg('重置成功', {
        icon: 1
      });
    });
  }
	var flag = false;
  form.on('submit(formDemo)', function (data) {
    if(flag){
    return false;
    }
    flag = true;
    console.log(data.field);
    $.post("{:url('Authgroup/edit')}", data.field, function (e) {
      if (e.code == '1') {
        // console.log('11111')
        layer.msg(e.msg, {
          icon: 1,
          time: 2000
        }, function () {
          window.location.href = e.data
        });
      } else {      
        layer.msg(e.msg, {
          icon: 2,
          time: 2000
        });
      }
    }, 'json')
    return false;    
  })
  // function add(){
  //         var title = $("#title").val();
  //         var status = $('input[name="status"]:checked').val();
  //         var id = $('input[name="id"]').val();
  //         var role = $('#role').val();
  //         if(title == ''){
  //                 layer.msg('请填写用户组名称', {icon: 2,time: 2000});
  //         }
  //         $.post("{:url('Authgroup/edit')}",{title:title,status:status,id:id,role:role},function(returndata){
  //                 if(returndata.code == '1'){
  //                  layer.msg(returndata.msg, {icon: 1,time: 2000},function(){window.location.href=returndata.data});
  //          }else{
  //                  layer.msg(returndata.msg, {icon: 2,time: 2000}); 
  //          }
  //         },'json')

  // }
</script>